<?php
    /*
        数据库访问与操作都在此
        关乎数据安全，修改请慎重
    */
    //获取我的信息
    if(!$_SESSION[openid]){
        $_SESSION[openid]=0;
    }
    // 获取我的数据
    function mGetMy(){
        return mfa(mq("select * from my_acount where openid='$_SESSION[openid]'"));
    }
    //获取回复
    function mGetReply($uid){
        return mq("SELECT 头像,昵称,时间,内容 FROM `my_reply`,`my_acount` WHERE my_reply.tid='$uid' and my_reply.sid=my_acount.openid");
    }
    //修改我的资料、
    function mSetMy($vars){
        mq("update my_acount set ".mMakeSet($vars)." where openid='$_SESSION[openid]'");
    }
    //获取评论
    function mGetReview($uid){
        return mq("SELECT 头像,昵称,时间,内容 FROM `my_review`,`my_acount` WHERE my_review.sid='$uid' and my_review.tid=my_acount.openid");
    }
    //获取系统消息
    function mGetSysmess($uid){
        return mq("select * from my_sysmess where uid='$uid'");
    }
    //获取访问我主页的人的信息，时间和是否对我红心
    function mGetHeart($uid){
        return mq("select my_acount.头像,my_acount.昵称,my_heart.时间 from my_heart,my_acount where my_heart.sid=my_acount.openid and my_heart.tid='$uid'");
    }
    //获取访问我主页的人的信息，时间和是否对我眨眼
    function mGetBlink($uid){
        return mq("select my_acount.头像,my_acount.昵称,my_blink.时间 from my_blink,my_acount where my_blink.sid=my_acount.openid and my_blink.tid='$uid'");
    }
    //获取积分
    function mGetPoint($uid){
        return mq("select * from my_acount where tid='$uid'");
    }
    // 获取相册
    function mGetAlbum($uid){
        return mq("select * from my_album where uid='$uid'");
    }
    // 获取为查看的消息数
    function mGetMymess(){
        $reply=mfa(mq("SELECT count(*) FROM `my_reply` WHERE `时间`>(select 查看回复时间 from my_acount where openid=$_SESSION[openid]) and tid=$_SESSION[openid]"));
        $review=mfa(mq("SELECT count(*) FROM `my_review` WHERE `时间`>(select 查看评论时间 from my_acount where openid=$_SESSION[openid]) and sid=$_SESSION[openid]"));
        $heart=mfa(mq("SELECT count(*) FROM `my_heart` WHERE `时间`>(select 查看红心时间 from my_acount where openid=$_SESSION[openid]) and tid=$_SESSION[openid]"));
        $blink=mfa(mq("SELECT count(*) FROM `my_blink` WHERE `时间`>(select 查看眨眼时间 from my_acount where openid=$_SESSION[openid]) and tid=$_SESSION[openid]"));
        $sysmess=mfa(mq("SELECT count(*) FROM `my_sysmess` WHERE `时间`>(select 查看系统消息时间 from my_acount where openid=$_SESSION[openid]) and uid=$_SESSION[openid]"));
        return(array('reply'=>$reply[0],'review'=>$review[0],'heart'=>$heart[0],'blink'=>$blink[0],'sysmess'=>$sysmess[0]));
    }
    // 获取积分兑换的图片和地址
    function mGetChange(){
        return mq("SELECT * FROM `my_change`");
    }
    function mGetVisit($uid){
        return mq("SELECT * FROM `my_visit`,`my_acount` where my_visit.sid='$uid' and my_acount.openid=my_visit.sid");
    }
    function mSetVisit($tid){
        return mq("INSERT INTO `my_visit`( `sid`, `tid`, `时间`) VALUES ($_SESSION[openid],$tid,'".date('Y-m-d h:m:s',strtotime('now'))."')");
    }
    // 获取帐号详细
    function mGetAcount($openid){
        return mfa(mq("select * from my_acount where openid=".$openid));
    }
    // 获取用户邀请次数
    function mGetInvite($uid){
        return mfa(mq("select count(*) from my_acount where 邀请者=".$uid));
    }
    // 获取积分详情
    function mGetDetail($uid){
        $reply=mGetReply($uid);
        $review=mGetReview($uid);
        $sysmess=mGetSysmess($uid);
        $heart=mGetHeart($uid);
        $blink=mGetBlink($uid);
        $visit=mGetVisit($uid);
        $invite=mGetInvite($uid);
        $point=0-mysql_num_rows($review)-mysql_num_rows($reply)-mysql_num_rows($heart)-mysql_num_rows($blink)-mysql_num_rows($visit)+10*$invite[0];
        return(array('point'=>$point,'reply'=>$reply,'review'=>$review,'sysmess'=>$sysmess,'heart'=>$heart,'blink'=>$blink,'visit'=>$visit));
    }